package cn.zc.config;

import cn.zc.interceptor.AdminInterceptor;
import cn.zc.interceptor.PCDeviceCheckInterceptor;
import cn.zc.interceptor.UserInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import cn.zc.interceptor.JwtTokenAdminInterceptor;
import java.util.List;

/**
 * 配置类，注册web层相关组件
 */
@Configuration
@Slf4j
public class WebMvcConfiguration extends WebMvcConfigurationSupport {

    @Autowired
    private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
    @Autowired
    private PCDeviceCheckInterceptor pcDeviceCheckInterceptor;
    @Autowired
    private AdminInterceptor adminInterceptor;
    @Autowired
    private UserInterceptor userInterceptor;

    /**
     * 注册自定义拦截器
     *
     * @param registry
     */
    protected void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注册自定义拦截器...");
//        registry.addInterceptor(jwtTokenAdminInterceptor)
//                .addPathPatterns("/**")
//                .excludePathPatterns("/login/test");
        registry.addInterceptor(jwtTokenAdminInterceptor)
                .addPathPatterns("/login/**");
        registry.addInterceptor(pcDeviceCheckInterceptor)
                .addPathPatterns("/user/**");
        registry.addInterceptor(adminInterceptor)
                .addPathPatterns("/user/**");
        registry.addInterceptor(userInterceptor)
                .addPathPatterns("/cource/studentList/**");
    }
//    @Override
//    protected void addCorsMappings(CorsRegistry registry) {
//        registry.addMapping("/**")
//                .allowedOrigins("*")
//                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
//                .allowedHeaders("*")
//                .allowCredentials(true)
//                .maxAge(3600);
//    }
}
